# -*- coding: UTF-8 -*-
from multiprocessing import Queue

class Junction():
    def __init__(self,x_coordinate,y_coordinate,z_coordinate,flow_in,flow_out1,total_flow):
        self.x_coordinate = x_coordinate
        self.y_coordinate = y_coordinate
        self.z_coordinate = z_coordinate
        self.flow_in = flow_in
        self.flow_out1 = flow_out1
        self.total_flow = total_flow

    def computeFlow(self,flow_out:Queue,flow_in:Queue):
        while True:
            self.flow_out1 = flow_out.get(True)
            self.flow_in = self.flow_out1
            #写总管流量到队列
            flow_in.put(self.flow_in)
            self.total_flow += self.flow_out1 * 1

class OneTotwo(Junction):
    def __init__(self,x_coordinate,y_coordinate,z_coordinate,flow_in,flow_out1,flow_out2,total_flow):
        super(OneTotwo,self).__init__(x_coordinate,y_coordinate,z_coordinate,flow_in,flow_out1,total_flow)
        self.flow_out2 = flow_out2

    def computeFlow(self,flow_out1:Queue,flow_out2:Queue,flow_in:Queue):
        while True:
            self.flow_out1 = flow_out1.get(True)
            self.flow_out2 = flow_out2.get(True)
            self.flow_in = self.flow_out1 + self.flow_out2
            flow_in.put(self.flow_in)
            self.total_flow += self.flow_in * 1

class OneTothree(Junction):
    def __init__(self,x_coordinate,y_coordinate,z_coordinate,flow_in,flow_out1,flow_out2,flow_out3,total_flow):
        super(OneTothree, self).__init__(x_coordinate,y_coordinate,z_coordinate,flow_in, flow_out1,total_flow)
        self.flow_out2 = flow_out2
        self.flow_out3 = flow_out3

    def computeFlow(self,flow_out1:Queue,flow_out2:Queue,flow_out3:Queue,flow_in:Queue):
        while True:
            self.flow_out1 = flow_out1.get(True)
            self.flow_out2 = flow_out2.get(True)
            self.flow_out3 = flow_out3.get(True)
            self.flow_in = self.flow_out1 + self.flow_out2 + self.flow_out3
            flow_in.put(self.flow_in)
            #每秒计算一次
            self.total_flow += self.flow_in * 1